package ren.kane.asdppp.transaction.cost;

import ren.kane.asdppp.Employee;
import ren.kane.asdppp.PayrollDatabase;
import ren.kane.asdppp.transaction.Transaction;
import ren.kane.asdppp.classification.CommissionedClassification;

import java.time.LocalDate;

/**
 * @author renrk(1275) on 2019-04-15 8:54 PM
 **/
public class SalesReceiptTransaction implements Transaction {

    private LocalDate date;

    private double amount;

    private int empId;

    public SalesReceiptTransaction() {
    }

    public SalesReceiptTransaction(LocalDate date, double amount, int empId) {
        this.date = date;
        this.amount = amount;
        this.empId = empId;
    }

    @Override
    public void execute() {
        Employee employee = PayrollDatabase.getEmployee(empId);
        if (null != employee) {
            CommissionedClassification commissionedClassification = (CommissionedClassification) employee.getPaymentClassification();
            if (null != commissionedClassification) {
                commissionedClassification.addSalesReceipt(new SalesReceipt(date, amount));
            }
        }
    }
}
